package cn.lili.modules.order.order.serviceimpl;

import cn.lili.modules.order.order.entity.dos.OrderFlow;
import cn.lili.modules.order.order.service.OrderFlowService;
import cn.lili.modules.order.order.service.OrderIntegrationService;
import cn.lili.modules.order.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单整合服务
 * <p>
 * 2023/5/4 11:37
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class OrderIntegrationServiceImpl implements OrderIntegrationService {

    private final OrderFlowService orderFlowService;

    private final OrderService orderService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pass(String id) {
        orderFlowService.pass(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void refuse(String id) {

        OrderFlow orderFlow = orderFlowService.refuse(id);
        orderService.cancel(orderFlow.getOrderSn(),"订单出库失败，自动取消","",null);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void force(String orderSn) {
        orderFlowService.force(orderSn);
    }
}
